package com.example.demo.factory.factory03;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @Description
 * @Author youxin
 * @Version V1.0.0
 * @Since 1.0
 * @Date 2021/12/23
 */
public class OrderPizza {
    SimpleFactory simpleFactory;
    public OrderPizza(SimpleFactory simpleFactory){
        setSimpleFactory(simpleFactory);
    }
    public void setSimpleFactory(SimpleFactory simpleFactory){
        this.simpleFactory=simpleFactory;
        do{
            Pizza pizza = simpleFactory.createPizza(getOrderType());
            if(pizza!=null){
                pizza.getPre();
                pizza.cookie();
                pizza.cut();
                pizza.box();
            }else {
                System.out.println("没有改类型的pizza,下单失败");
                break;
            }

        }while (true);
    }

    private String  getOrderType(){
        try {
            BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
            System.out.println("input pizza type:");
            String str=bf.readLine();
            return str;
        }catch (IOException ioException){
            ioException.printStackTrace();
            return "";
        }
    }
}
